package com.itheima.网络编程.tcp编程.tcp编程.TCP;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class tcpkuozhan服务端 {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        while (true) {
            Socket accept = ss.accept();
            BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
//            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day16 网络编程\\"+System.currentTimeMillis()+".txt"));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day16 网络编程\\"+ UUID.randomUUID().toString()+".txt"));
            byte[] bys = new byte[1024];
            int len;
            while ((len = bis.read(bys)) != -1) {
                bos.write(bys, 0, len);
                bos.flush();
            }
            System.out.println("==============================");
            BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
            bw.write("接收成功");
            bw.flush();
            bw.close();
            bos.close();
            bis.close();
            accept.close();
        }
        //ss.close();

    }


}
